home *** CD-ROM | disk | FTP | other *** search
- package symantec.itools.db.pro;
-
- import java.util.Enumeration;
- import java.util.Hashtable;
- import java.util.Vector;
- import symantec.itools.db.net.BinaryInputStream;
- import symantec.itools.db.net.BinaryOutputStream;
- import symantec.itools.db.net.NetRecord;
- import symjava.sql.SQLException;
-
- class RecordSet {
- private RelViewPos _relPos;
- private Hashtable _recTrees;
- private boolean _allDataRead;
-
- RecordSet(RelViewPos relPos) {
- this._relPos = relPos;
- this._recTrees = new Hashtable();
- this._allDataRead = false;
- }
-
- synchronized void freeRecordTrees() {
- Enumeration e = this._recTrees.elements();
-
- while(e.hasMoreElements()) {
- RecordTree t = (RecordTree)e.nextElement();
- if (t != null) {
- t.freeRecordBlocks();
- }
- }
-
- this._recTrees.clear();
- this._relPos = null;
- this._allDataRead = false;
- }
-
- RecordTree getRecordTree(RelViewPos pos) throws SQLException {
- return this.getRecordTree(pos.getRecNum());
- }
-
- NetRecord getRecord(int recNum) throws SQLException {
- RecordTree t = this.getRecordTree(recNum);
- return t.getRecord();
- }
-
- synchronized void notifyRecChanged(NetRecord rec) throws SQLException {
- if (this._relPos != null) {
- this._relPos.notifyServerOfDataChange(rec);
- }
-
- }
-
- synchronized void deleteRecord(NetRecord rec) throws SQLException {
- if (this._relPos != null) {
- this._relPos.deleteServerRecord(rec, rec.getRecordNum());
- }
-
- }
-
- boolean isRecordTreeStored(int recNum) {
- return this._recTrees.containsKey(new Integer(recNum));
- }
-
- void storeRecordTree(RecordTree t) {
- NetRecord r = t.getRecord();
- if (!this.isRecordTreeStored(r.getRecordNum())) {
- this._recTrees.put(new Integer(r.getRecordNum()), t);
- }
-
- }
-
- synchronized NetRecord getNewRecord() throws SQLException {
- if (this._relPos != null) {
- NetRecord r = this._relPos.getNewServerRecord();
- RecordTree t = new RecordTree(r);
- this.storeRecordTree(t);
- return r;
- } else {
- return new NetRecord();
- }
- }
-
- synchronized void undoRecord(NetRecord rec) throws SQLException {
- if (this._relPos != null) {
- this._relPos.undoServerRecord(rec, rec.getRecordNum());
- }
-
- }
-
- synchronized BinaryInputStream getRemoteInputStream(int recID, int colIndex) throws SQLException {
- if (this._relPos != null) {
- return this._relPos.getRemoteInputStream(recID, colIndex);
- } else {
- throw new SQLException("Invalid Record block.");
- }
- }
-
- BinaryOutputStream getRemoteOutputStream(int recID, int colIndex) throws SQLException {
- if (this._relPos != null) {
- return this._relPos.getRemoteOutputStream(recID, colIndex);
- } else {
- throw new SQLException("Invalid Record block.");
- }
- }
-
- private synchronized RecordTree getRecordTree(int recNum) throws SQLException {
- NetRecord r = null;
- RecordTree t = null;
- if (this._relPos == null) {
- return new RecordTree();
- } else if (recNum == 0) {
- return new RecordTree();
- } else if (this.isRecordTreeStored(recNum)) {
- return (RecordTree)this._recTrees.get(new Integer(recNum));
- } else if (this._allDataRead) {
- return new RecordTree();
- } else {
- int rowsToRequest = this._relPos.getRowsToRequest();
- int reqNum = recNum - this._recTrees.size() > rowsToRequest ? recNum - this._recTrees.size() : rowsToRequest;
- Vector results = this._relPos.fetchRecords(this._recTrees.size() + 1, reqNum);
-
- for(int i = 0; i < results.size(); ++i) {
- r = (NetRecord)results.elementAt(i);
- t = new RecordTree(r);
- this.storeRecordTree(t);
- if (r.getState() == 105) {
- this._allDataRead = true;
- }
- }
-
- if (this.isRecordTreeStored(recNum)) {
- return (RecordTree)this._recTrees.get(new Integer(recNum));
- } else {
- return new RecordTree();
- }
- }
- }
- }
-